import json


def ui():
    from src.apps.shoudongfasong.ui_demo import ZCAN_Demo
    demo = ZCAN_Demo()
    demo.mainloop()


def zuds():
    from src.zuds.zuds_test_main import zuds_test
    zuds_test()


def shoudong_uds():
    from src.apps.uds_ui.base_ui import uds_manual
    uds_manual()


def serve_func():
    from src.apps.uds_ui.server_lib import serve_test
    serve_test()


def c62x_zuoyianmo():
    from src.apps.uds_ui.base_ui import init_masterUI
    # 下面的这个导入要在init_masterUI之后，否则会报警循环引用
    from src.apps.zuoyianmo.c62x_zuoyianmo import seat_test_window

    masterUI = init_masterUI()

    import time
    time.sleep(1)
    parentWin = masterUI.can_unitTab

    seat_test_window(masterUI, parentWin)

    masterUI.mainloop()
    # FIXME: ui.mainloop后面的代码都不会执行
    # seat_test_window(ui)


def batc_b60v_zuoyianmo():
    from src.apps.uds_ui.base_ui import init_masterUI
    # 下面的这个导入要在init_masterUI之后，否则会报警循环引用
    from src.apps.zuoyianmo.batc_b60v_zuoyianmo import seat_test_window

    masterUI = init_masterUI()

    import time
    time.sleep(1)
    parentWin = masterUI.can_batc_unitTab

    seat_test_window(masterUI, parentWin)

    masterUI.mainloop()


# 建立appname和运行程序的映射
app_dict = {
    "base": shoudong_uds,
    "c62x_zuoyianmo": c62x_zuoyianmo,
    "batc_b60v_zuoyianmo": batc_b60v_zuoyianmo
}


if __name__ == '__main__':
    with open('./config/app_config.json', 'r', encoding='utf-8') as f:
        app_config = json.load(f)
        print(app_config)

    app_name = app_config['app_select']
    app_dict[app_name]()
    # zuoyianmo()

    pass
